package com.taoyibao.hongcanting.ui.home.delegate;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.delegate.BackToolbarDelegate;
import com.taoyibao.hongcanting.model.CouponModel;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * @author TangAnna
 * @description: 选择优惠券
 * @date :${DATA} 11:50
 */
public class ChooseCouponDelegate extends BackToolbarDelegate {
    private RecyclerView mRecyclerView;
    private List<CouponModel> mData;
    private CommonAdapter mAdapter;

    @Override
    public int getRootLayoutId() {
        return R.layout.activity_choose_coupon;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        setTitle("选择优惠券");
        mData = new ArrayList<>();
        mRecyclerView = get(R.id.rv_chooseCoupon_list);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        mRecyclerView.setAdapter(mAdapter = new CommonAdapter<CouponModel>(getActivity(), R.layout.item_coupon, mData) {
            @Override
            protected void convert(ViewHolder holder, CouponModel couponModel, int position) {
                holder.getView(R.id.rb_item_coupon_check).setVisibility(View.VISIBLE);
            }
        });
        setData(mData);
    }

    /**
     * 设置优惠券的数据
     *
     * @param data
     */
    public void setData(List<CouponModel> data) {
//        if (data == null || data.size() < 1) {
//            setEmptyView(true);
//            return;
//        }
        mData.clear();
        for (int i = 0; i < 4; i++) {
            mData.add(new CouponModel());
        }
//        mData.addAll(data);
        mAdapter.notifyDataSetChanged();
    }

    /**
     * 设置空页面
     *
     * @param b true 显示空页面  false显示数据页面
     */
    public void setEmptyView(boolean b) {
        get(R.id.emptyView).setVisibility(b ? View.VISIBLE : View.GONE);
        get(R.id.dataView).setVisibility(b ? View.GONE : View.VISIBLE);
    }
}
